package com.jier.service.impl;

import com.jier.common.Page;
import com.jier.common.Result;
import com.jier.dao.SystemRoleDao;
import com.jier.entities.SystemRole;
import com.jier.enums.RoleType;
import com.jier.service.ISystemRoleService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 系统角色业务实现类
 *
 * @author jie_r
 * @date 2018/03/08
 */
@Service
public class SystemRoleServiceImpl extends BaseServiceImpl<SystemRoleDao, SystemRole> implements ISystemRoleService {
    @Override
    public SystemRole getSystemRole(Integer systemUserId) throws Exception {
        return mapper.getSystemRole(systemUserId);
    }

    @Override
    public Result<SystemRole> getSystemRoles(Page page) throws Exception {
        return getRecordPage("getSystemRoles", page, null);
    }

    @Override
    public List<SystemRole> getSystemRoles() throws Exception {
        Example example = getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("type", RoleType.normalAdmin.ordinal());
        criteria.andEqualTo("status", Boolean.TRUE);
        return getByExample(example);
    }

    @Override
    public SystemRole getSystemRoleByName(String name) throws Exception {
        Example example = getExample();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("name", name);
        return getUniqueByExample(example);
    }
}
